<?php
//$moduleid = 30;
include '../../common.inc.php';
$dbSql = new PDO('mysql:host=192.168.1.19;dbname=ixdcw', 'root', 'root');
$ds       = $dbSql->query('select count(*) as num from xd_video');
$fo       = $ds->fetchObject();
$num      = intval($fo->num);
if (!isset($start)) {
	$start = 0;
} else {
	if ($start > $num) {
		die(date('Y-m-d H:i:s'));
	}
}
$sql    = "select * from xd_video where itemid > $start limit 10";
$result = $dbSql->query($sql);
$rs     = $result->fetchAll();
foreach ($rs as $r) {
//	var_dump($r['thumb']);
	$local = 'F:/Users/Mark/Documents/video'.str_replace('file/video','', $r['thumb']);
	if (file_exists($local)) {
		$remoteName =  Picture::name(10, 1, File::ext($r['thumb']));
		$url = Picture::url($remoteName);
		var_dump($url);
		Picture::saveFile($local,$remoteName);
		$sql = Sql::update('xd_video', "img='{$url}'", 'itemid='.$r['itemid']);
		$dbSql->query($sql);
	}
	$start=$r['itemid'];
}

echo '<meta http-equiv="refresh" content="0; url='.$_SERVER['PHP_SELF'].'?start='.$start.'" />';